package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.bean.PointsBean;

import java.text.DecimalFormat;
import java.util.List;

public class PointsAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<PointsBean> mPointsBean;
    private String TAG="AgentAdapter";
    public PointsAdapter(Context context, List<PointsBean> maxPointsBeanDatas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mPointsBean = maxPointsBeanDatas;
    }


    @Override
    public int getCount() {
        return mPointsBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mPointsBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.points_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.mPoint_uid = convertView.findViewById(R.id.point_uid);
            viewHolder.mPoint_day = convertView.findViewById(R.id.point_day);
            viewHolder.mPoint_money = convertView.findViewById(R.id.point_money);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        PointsBean pointsBean = mPointsBean.get(position);
        viewHolder.mPoint_uid.setText(pointsBean.getUid());

        String time=pointsBean.getDay();
        String nian=time.substring(0,4);
        String yue=time.substring(5,7);
        String ri=time.substring(8,10);


        viewHolder.mPoint_day.setText(yue+"月"+ri+"日"+"总汇");

        String s=pointsBean.getMoney();
        s=s.substring(0,1);
        if(s.equals("-")){
            Double a1 = Double.parseDouble(pointsBean.getMoney());
            DecimalFormat decimalFormatq = new DecimalFormat("0.00");
            String b1 = decimalFormatq.format(a1);
            viewHolder.mPoint_money.setText(b1);
             viewHolder.mPoint_money.setTextColor(Color.parseColor("#333333"));
        }else{
            Double a1 = Double.parseDouble(pointsBean.getMoney());
            DecimalFormat decimalFormatq = new DecimalFormat("0.00");
            String b1 = decimalFormatq.format(a1);
            viewHolder.mPoint_money.setText(b1);
            viewHolder.mPoint_money.setTextColor(Color.parseColor("#F0562E"));
        }



        Double a1 = Double.parseDouble(pointsBean.getMoney());
        DecimalFormat decimalFormatq = new DecimalFormat("0.00");
        String b1 = decimalFormatq.format(a1);

        viewHolder.mPoint_money.setText(b1);
        return convertView;
    }


    public static class ViewHolder{
        TextView mPoint_uid;
        TextView mPoint_day;
        TextView mPoint_money;
    }
}
